<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" media="screen" href="../../css/bootstrap.min.css">
</head>
<body>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
    <form class="form-horizontal" onsubmit="return false" id="form">
        <fieldset>
            <input type="hidden" id="id" name="id">
            <div class='form-group'>
                <label class='col-md-2 control-label'>名称</label>
                <div class='col-md-10'>
                    <input readonly="readonly" class='form-control' placeholder='name' type='text' name='name' id='name' data-bv-notempty='true' data-bv-notempty-message='name 不能为空'>
                </div>
            </div>
            <div class="form-actions">
                <div class="row" align="center">
                    <div class="col-md-12">
                        <button class="btn btn-primary" onclick="location.href='mfflServiceList.html'">返回</button>
                        <button class="btn btn-primary" type="submit" onclick="update()">
                            <i class="fa fa-save"></i> 保存
                        </button>
                    </div>
                </div>
            </div>

        </fieldset>
    </form>
</div>
<script type="text/javascript" src="../../js/libs/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="../../js/jq.js"></script>
<script type="text/javascript" src="../../js/plugin/bootstrapvalidator/bootstrapValidator.min.js"></script>
<script type="text/javascript" src="../../js/common.js"></script>
<script type="text/javascript" src="../../layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['layer', 'laydate'], function () {
        var layer = layui.layer;
    });

    initData();

    function initData() {
        var id = getUrlParam("id");
        if (id != "") {
            $.ajax({
                type: 'get',
                url: '/mfflServices/' + id,
                async: false,
                success: function (data) {
                    if (data.id != 6 && data.id != 2) {
                        $("fieldset .form-group").eq(-1).after("<div class='form-group'> <label class='col-md-2 control-label' id='confirmTime_title'></label> <div class='col-md-10'> <input class='form-control' placeholder='confirmTime' type='text' name='confirmTime' id='confirmTime' data-bv-notempty='true' data-bv-notempty-message='confirmTime 不能为空'> </div> </div> <div class='form-group'> <label class='col-md-2 control-label' id='refuseTime_title'></label> <div class='col-md-10'> <input class='form-control' placeholder='RefuseTime' type='text' name='refuseTime' id='RefuseTime' data-bv-notempty='true' data-bv-notempty-message='RefuseTime 不能为空'> </div> </div>");
                    }
                    if (data.id != 2) {
                        $("fieldset .form-group").eq(-1).after("<div class='form-group'> <label class='col-md-2 control-label'>律师收费最大金额/元</label> <div class='col-md-10'> <input class='form-control' placeholder='maximumMoney' type='text' name='maximumMoney' id='maximumMoney' data-bv-notempty='true' data-bv-notempty-message='maximumMoney 不能为空'> </div> </div> <div class='form-group'> <label class='col-md-2 control-label'>律师收费最小金额/元</label> <div class='col-md-10'> <input class='form-control' placeholder='minimumMoney' type='text' name='minimumMoney' id='minimumMoney' data-bv-notempty='true' data-bv-notempty-message='minimumMoney 不能为空'> </div> </div>");
                    }

                    // if (data.id == 2) {
                    //     $("fieldset .form-group").eq(-1).after("<div class='form-group'> <label class='col-md-2 control-label' id='money_title'>悬赏金额/元(英文分号分割)</label> <div class='col-md-10'> <input class='form-control' placeholder='money' type='text' name='money' id='money' data-bv-notempty='true' data-bv-notempty-message='money 不能为空'> </div> </div> <div class='form-group'> <label class='col-md-2 control-label' id='days_title'>悬赏时间/天(英文逗号分割)</label> <div class='col-md-10'> <input class='form-control' placeholder='days' type='text' name='days' id='days' data-bv-notempty='true' data-bv-notempty-message='days 不能为空'> </div> </div>");
                    // }

                     if (data.id == 2) {
                         $("fieldset .form-group").eq(-1).after("<div class='form-group'> <label class='col-md-2 control-label'>律师收费最小金额/元</label> <div class='col-md-10'> <input class='form-control' placeholder='minimumMoney' type='text' name='minimumMoney' id='minimumMoney' data-bv-notempty='true' data-bv-notempty-message='minimumMoney 不能为空'> </div> </div>");
                     }

                    if (data.id == 6) {
                        $("fieldset .form-group").eq(-1).after("<div class='form-group'> <label class='col-md-2 control-label'>图文咨询体验时间/分钟</label> <div class='col-md-10'> <input class='form-control' placeholder='freeapplytime' type='text' name='freeapplytime' id='freeapplytime' data-bv-notempty='true' data-bv-notempty-message='freeapplytime 不能为空'> </div> </div></div> </div> <div class='form-group'> <label class='col-md-2 control-label' id='days_title'>购买时长/小时</label> <div class='col-md-10'> <input class='form-control' placeholder='days' type='text' name='days' id='days' data-bv-notempty='true' data-bv-notempty-message='days 不能为空'> </div> </div>");
                    }

                    $('#id').val(data.id);
                    $('#name').val(data.name);
                 // $('#money').val(data.money);//金额
                    $('#days').val(data.days);//天数(图文咨询所用-保留)
                    $('#computingUnit').val(data.computingUnit);//计算单位（/天/次）
                    $('#maximumMoney').val(data.maximumMoney);//最大金额
                    $('#minimumMoney').val(data.minimumMoney);//最小金额
                    if (data.id == 2) {
                        $("#confirmTime_title").text("用户超时未设为最佳答案时长/天");
                    } else {
                        $("#confirmTime_title").text("用户超时未点击确认完成/天");
                    }
                    $('#confirmTime').val((((data.confirmTime / 1000) / 60) / 60) / 24);
                    if (data.id == 2) {
                        $("#refuseTime_title").text("咨询未被回复超时退款时长/天");
                    } else {
                        $("#refuseTime_title").text("律师超时未接受自动退款时长/天");
                    }
                    $('#RefuseTime').val((((data.refuseTime / 1000) / 60) / 60) / 24);
                    $('#freeapplytime').val(((data.freeapplytime / 1000)) / 60);//图文咨询默认时间毫秒转换为分钟

                }
            });
        }
    }

    function update() {
        $('#form').bootstrapValidator();
        var bootstrapValidator = $("#form").data('bootstrapValidator');
        bootstrapValidator.validate();
        if (!bootstrapValidator.isValid()) {
            return;
        }
        var formdata = $("#form").serializeObject();
        console.log(JSON.stringify(formdata));
        $.ajax({
            type: 'put',
            url: '/mfflServices',
            contentType: "application/json; charset=utf-8",
            data: JSON.stringify(formdata),
            success: function (data) {
                layer.msg("修改成功", {shift: -1, time: 1000}, function () {
                    location.href = "mfflServiceList.html";
                });
            }
        });
    }
</script>
</body>
</html>
